home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / RTF / elements.C < prev    next >
C/C++ Source or Header  |  1994-08-01  |  2KB  |  117 lines

  1. /* $Header: /usr/people/pcd/Src/RTF/RCS/elements.C,v 1.1 92/11/23 12:58:54 pcd Exp Locker: pcd $
  2.  */
  3.  
  4. #include "elements.h"
  5. #include "rtftoken.h"
  6. #include "view.h"
  7.  
  8. #include "debug.h"
  9.  
  10. Inches ParagraphFormat::default_tab_width_;
  11. int debug_tabs = 0;
  12.  
  13. Qty
  14. NewLineFlow::character_shape(TextPosition, Qty q,
  15.                  Extent avail, Extent& used, int) const
  16. {
  17.   Coord h = font_ascent() + space_after();
  18.   REQUIRE(h <= avail.bottom() - avail.top()
  19.       && avail.right() > avail.current_x(), return 0);
  20.  
  21.   used.ascent(font_ascent());
  22.   used.descent(space_after());
  23.  
  24.   /* x2 is space left to justify... */
  25.   used.x2 = used.x0 = avail.right() - avail.current_x();
  26.   return q;
  27. }
  28.  
  29.  
  30. ParagraphFormat::ParagraphFormat()
  31. {
  32.   normal();
  33. }
  34.  
  35.  
  36. void
  37. ParagraphFlow::line_shape(TextPosition where, Extent& margins) const
  38. {
  39.   /* find first renderable TextPosition */
  40.   LRBox a(0), b(0);
  41.   Extent avail(0,0,1,0,0); // minimal
  42.   Extent used;
  43.   TextPosition aa = a.format(this, 0, bytes(), avail, used);
  44.   TextPosition bb = b.format(this, where, bytes(), avail, used);
  45.  
  46.   margins.x1 = view().hinches(fmt_.left_indent);
  47.   margins.y0 = 0;
  48.  
  49.   if(aa == bb){
  50.     margins.x1 += view().hinches(fmt_.first_indent);
  51.     margins.y0 = view().vinches(fmt_.space_before);
  52.   }
  53.  
  54.   switch(fmt_.justification){
  55.   case ParagraphFormat::quad_center:
  56.     margins.x0 = 2;
  57.     break;
  58.  
  59.   case ParagraphFormat::quad_right:
  60.     margins.x0 = 1;
  61.     break;
  62.  
  63.   default:
  64.     margins.x0 = 0;
  65.     break;
  66.   }
  67.  
  68.   margins.x2 = view().hinches(fmt_.right_indent);
  69.   margins.y1 = view().vinches(fmt_.space_between);
  70. }
  71.  
  72.  
  73. Coord
  74. TabFlow::next_tab_stop(Coord here) const
  75. {
  76.   int i;
  77.   Coord x;
  78.  
  79.   for(i=0; here > (x = view().hinches(fmt_.tab(i))); i++);
  80.  
  81.   return x;
  82. }
  83.  
  84.  
  85. Qty
  86. TabFlow::character_shape(TextPosition, Qty q,
  87.              Extent avail, Extent& used, int w) const
  88. {
  89.   Coord x = avail.x0 + next_tab_stop(avail.current_x() - avail.x0);
  90.  
  91.   used.y0 = 1;
  92.   used.y1 = 0;
  93.   used.x2 = 0;
  94.  
  95.   Debug(tabs, ("tab? left:%d tab: %d(%g) right: %d\n",
  96.            avail.x0, x, tx_, avail.x2));
  97.  
  98.   if(x > avail.right() || avail.current_x() >= avail.right()){
  99.     if(w == 0){ // don't need to fit whole tab.
  100.       used.x0 = avail.right() - avail.current_x();
  101.       return q;
  102.     }else
  103.       return 0;
  104.   }
  105.  
  106.   used.x0 = x - avail.current_x();
  107.   if(used.x0 < 0) used.x0 = 0;
  108.  
  109.   return q;
  110. }
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.